<?php
/**
 * @package		Joomla.Administrator
 * @subpackage	com_users
 * @copyright	Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access.
defined('_JEXEC') or die;

// Load the tooltip behavior.
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('behavior.modal');

$canDo = UsersHelper::getActions();
$user = JFactory::getUser();
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$loggeduser = JFactory::getUser();
?>

<form action="<?php echo JRoute::_('index.php?option=com_users&view=users');?>" method="post" name="adminForm" id="adminForm">
	<?php if(!$this->checkEO){ ?>
    <fieldset id="filter-bar">
		
        <table style="width: 800px;" border=0>
            <tr>
                <td style="width: 20%;"><label>センター・クラブ種別</label></td>
                <td>
                    <select id="user_type" name="user_type" class="inputbox big">
                        <option value="all" <?php if(JRequest::getVar('user_type','all')=='all') echo 'selected' ?>>指定しない </option>
                        <option value="0" <?php if(JRequest::getVar('user_type','all')=='0') echo 'selected' ?>>センター </option>
                        <option value="1" <?php if(JRequest::getVar('user_type','all')=='1') echo 'selected' ?>>クラブ </option>
                    </select>
                </td>
                <td><label> 都道府県</label></td>
                <td>
                    <select id="pref" name="pref" class="inputbox big">
                        <option value="all">指定しない </option>
                        <?php
                            foreach($this->prefs as $key => $row){
                                $selected = JRequest::getVar('pref','')==$row->PREF_CODE ? 'selected':'';
                                echo "<option value='$row->PREF_CODE' $selected >$row->PREF_NAME</option>";
                            } 
                        ?>
                    </select>
                </td>
                <td style="width:150px;">	
                    <button type="button" onclick="Joomla.submitbutton('search')"  class="btn" >検索</button>
                    <button type="button" class="button" onclick="document.id('user_type').value='all';document.id('pref').value='all';
                        document.id('ocba_name').value='';document.id('ocba_code').value='';
                        this.form.submit();">クリア</button>
                </td>
            </tr>
            <tr>
                <td><label>センター・クラブ名</label></td>
                <td><input type="text" name="ocba_name" id="ocba_name" class="inputbox medium" value="<?php echo JRequest::getVar('ocba_name') ?>" /></td>
                <td><label> センター・クラブコード</label></td>
                <td><input type="text" name="ocba_code" id="ocba_code" class="inputbox medium" value="<?php echo JRequest::getVar('ocba_code') ?>" /></td>
                <td>&nbsp;</td>
            </tr>
        </table>
		
	</fieldset>
    <?php } ?>
	<div class="clr"> </div>

	<table class="adminlist">
		<thead>
			<tr>
				<th width="5%">
					<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
				</th>
				<th class="nowrap" width="10%">
					<?php echo "<lablel class='labelth'>ユーザーID</label>"; ?>
				</th>
				<th class="nowrap" width="20%">
					<?php echo "<lablel class='labelth'>所属</label>"; ?>
				</th>
				<th class="nowrap" width="20%">
					<?php echo "<lablel class='labelth'>氏名</label>"; ?>
				</th>
				<th class="nowrap" width="20%">
					<?php echo "<lablel class='labelth'>権限グループ</label>"; ?>
				</th>
				<th class="nowrap" width="25%">
					<?php echo "<lablel class='labelth'>メールアドレス</label>"; ?>
				</th>

			</tr>
		</thead>
		<tfoot>
			<tr>
				<td colspan="15">
					<?php echo $this->pagination->getListFooter(); ?>
				</td>
			</tr>
		</tfoot>
		<tbody>
        <?php
        if($this->items != null){   
            foreach($this->items as $key=>$row){
                $row_cls = $key % 2;                
                echo "<tr class='row$row_cls'>
        				<td class='center'>
                            <input type='checkbox' id='cb$row->id' name='cid[]' value='$row->id' onclick=\"_checked(this.checked);\"/>                        
        				</td>
                        <td class='center'>
                            <a href='index.php?option=com_users&task=user.edit&id=$row->id'>$row->username</a> 
                        </td>             
                        <td class='center'>
                            $row->ocba_name                        
        				</td>
                        <td class='center'>
                            $row->name                        
        				</td>
                        <td class='center'>
                            $row->group_name                        
        				</td>
                        <td class='center'>
                            $row->email                        
        				</td>
        			</tr>";
                            
            }
        }else{
            echo '<tr><td colspan="6" align="center">データは見つかりませんでした</td></tr>';
        } 
        ?>
			</tr>
		</tbody>
	</table>


	<div>
		<input type="hidden" name="task" value="" />
		<input type="hidden" id="boxchecked" name="boxchecked" value="0" />
		<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
		<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
		<?php echo JHtml::_('form.token'); ?>
	</div>
</form>

<script>
    Joomla.submitbutton = function(task){
	   if(task == 'users.delete'){
	       if(!confirm("選択されたユーザを削除します。\nよろしいですか？")){
	           return false;
	       }
	   }
       
       Joomla.submitform(task, document.getElementById('adminForm'));
       
    };

    
    jq('#clear').click(function(event){
        location.reload();
    });

    function _checked(value){
        var boxchecked = document.adminForm.boxchecked;
        if(boxchecked.value < 0)
            return;
        var val = boxchecked.value;
        val += value == true ? 1 : -1;
        boxchecked.value = val;
    }
</script>
